;:sys58451
sys36864
	;.opt oo
	*= $c000
invec	=$302
inold	=$a483
getline	=$a560
incont	=$a48a
strout	=$ab1e
chrget	=$7a
puff	=512
shell	=$a000
konf	=1
shellend	=$c000 	; lowbyte 0
tmp	=247
irqvec	=$314
numbkey	=198
keybuf	=631
from	=249
cr	=13
quote	=212
key	=203
shift	=653
konf0	=0
tmp2	=251
screen	=$e000
farbram	=55296
scn	=648
startpos	=3
fen	=253
col	=166
curs	=646
rd	=168
qkeys	=$ea87
rundel	=7
timer	=56325
fn2	=181
maxlines	=23
t1	=maxlines+1
t2	=t1*40
t3	=t2+startpos
schirm	=283
resvkt	=$fffc
	jmp losgehts
	jsr quit
hello	.byte "\x05\xa4\xa4\xa4\xa4\xa4\xa4\xa4\xa4\xa4\xa4\xa4\xa4\xa4\xa4\xa4\xa4\xa4\xa4\xa4\xa4\xa4\xa4\xa4\xa4"
	.byt 13
	.byte "\x12  cbm 64: hot keys 1.0  "
	.byt 13
	.byte "\x12prg. by nikolaus heusler"
	.byt 13
	.byte "\x12nh-070488-arr    (c) nss\x11"
	brk
text1	.byt 136,143,148,160,139,133,153,147,186
	.byte "\xa0\xa0\xa0\xa0\xa0\xa0\xa0"
	.byt 150,177,174,176
	.byte "\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0"
	.byt 168,131,169,160,142,147,147,184,184
opt	.byt 143,144,148,137,143,142,147,186
	.byte "\xa0\xa0\xa0\xa0"
	.byt 142,147,147,184,184
	.byt 160,148,129,139,133,160,144,146,135,173,140
	.byt 142,147,174
	.byte "\xa0\xa0\xa0\xa0"
	.byt 146,133,147,133,148
	.byte "\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0"
	.byt 147,151,137,148,131,136,160,143,134,134
	.byte "\xa0\xa0\xa0\xa0\xa0\xa0\xa0"
	.byt 131,140,133,129,146,160,141,133,141,143,146,153
	.byte "\xa0\xa0\xa0\xa0\xa0"
	.byt 134,133,142,147,148,174,130,146,133,137,148,133
	.byte "\xa0\xa0\xa0\xa0\xa0"
	.byt 141,133,141,143,146,153,186
	.byte "\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0"
	.byt 164,160,160,160,160,173,164
	.byte "\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0"
	.byt 134,146,133,133,186,160,131,129,174,164
	.byte "\xa0\xa0\xa0\xa0\xa0\xa0"
	.byt 147,148,129,148,133,141,133,142,148,147,186
	.byte "\xa0\xa0\xa0\xa0\xa0"
	brk
write	.word 0
owrite	.word 0
oldirq	.word $ea31
flag	brk
modus	brk
oldkey	brk
anzdrin	brk
takeprg	brk
zeile	brk
merky	brk
fin	brk
fiy	brk
nummer	brk
keylock	.word 0
delay	brk
lastkey	brk
linus	brk
menpt	brk
breit	brk
hex	.byt 176,177,178,179,180,181,182,183,184
	.byt 185,129,130,131,132,133,134
dez	.byt 100,10,1
adr	.word takejn,reset,quit,cleara,cbreit
putfrom	php
	sei
	inc flag
	sta modus
	stx from
	sty from+1
	plp
	lda #4
	sta timer
nichts	rts
testvoll	ldy #-1
harry	iny
	lda puff,y
	beq nichts
	cmp #32
	beq harry
warwas	cmp #"0"
	bcc nichts
	cmp #"9"+1
	bcs nichts2
	lda takeprg
	rts
nichts2	lda #-1
	rts
savescreen	ldy #0
	sty tmp
	sty tmp2
	lda scn
	sta tmp+1
	lda #>screen
	sta tmp2+1
	ldx #4
ab1a	lda (tmp),y
	sta (tmp2),y
	dey
	bne ab1a
	inc tmp+1
	inc tmp2+1
	dex
	bne ab1a
	ldx #4
	lda #>farbram
	sta tmp+1
ab1b	lda (tmp),y
	sta (tmp2),y
	dey
	bne ab1b
	inc tmp+1
	inc tmp2+1
	dex
	bne ab1b
	rts
loadscreen	jsr ram
	ldy #0
	sty tmp
	sty tmp2
	lda scn
	sta tmp+1
	lda #>screen
	sta tmp2+1
	ldx #4
ab2a	lda (tmp2),y
	sta (tmp),y
	dey
	bne ab2a
	inc tmp+1
	inc tmp2+1
	dex
	bne ab2a
	ldx #4
	lda #>farbram
	sta tmp+1
ab2b	lda (tmp2),y
	sta (tmp),y
	dey
	bne ab2b
	inc tmp+1
	inc tmp2+1
	dex
	bne ab2b
	jmp rom
docol	lda fen
	sta col
	lda fen+1
	and #3
	ora #>farbram
	sta col+1
raus	rts
keys	lda #64
	sta key
	dec keylock
	bne raus
	dec keylock+1
	bpl raus
	lda delay
	sta keylock+1
	jsr qkeys
	lda key
	cmp lastkey
	bne neu
	dec delay
	bpl raus
	lda #0
	sta delay
	rts
neu	sta lastkey
	lda #rundel
	sta delay
	rts
schauende	ldy merky
	dey
sucs	iny
	lda (rd),y
	bne sucs
	sty fiy
	rts
ram	lda #53
	.byt $2c
rom	lda #55
	sta konf
	rts
flare	ldy #0
	lda (col),y
	clc
	adc #1
	sta (col),y
	jsr keys
	lda key
	cmp #7
	rts
crestore	lda curs
	ldy #0
	sta (col),y
	lda shift
	rts
jnout	=*
	lda scn
	sta fen+1
	lda #55
	sta fen
	lda takeprg
	bne nimm2
	lda #142
	.byt $2c
nimm2	lda #138
	ldy #0
	sta (fen),y
	rts
breitout	lda #213
	ldy scn
	sta fen
	sty fen+1
	ldx breit
	inx
	txa
	jsr dezout
	lda #160
	ldy #0
	sta (fen),y
	rts
windowout	lda scn
	ldy #startpos
	sta fen+1
	sty fen
	jsr docol
	ldy breit
bro	lda text1,y
	sta (fen),y
	lda curs
	sta (col),y
	dey
	bpl bro
	lda #<shell
	ldy #>shell
	sta rd
	sty rd+1
	lda #0
	sta zeile
	sta linus
	jsr ram
loop1	lda rd+1
	cmp write+1
	bcc loop2
	bne qloop3
	lda rd
	cmp write
	bcc loop2
qloop3	jmp loop3
qqloop3	dec zeile
	bne qloop3
loop2	inc zeile
	lda zeile
	cmp #maxlines+2
	bcs qqloop3
	lda breit
	sta fiy
	lda fen
	clc
	adc #40
	sta fen
	bcc loop4
	inc fen+1
loop4	jsr docol
	ldy #0
	sty fin
	dey
loop5	iny
	jsr outit
	sta (fen),y
	lda curs
	sta (col),y
	cpy breit
	bcc loop5
	lda fin
	bne ended
	jsr schauende
ended	ldy fiy
	iny
	tya
	clc
	adc rd
	sta rd
	bcc qloop1
	inc rd+1
qloop1	jmp loop1
loop3	jsr rom
	lda #startpos+40
	ldy #>farbram
	sta col
	sty col+1
	lda #0
	sta nummer
cursor	jsr flare
	beq updown
	cmp #1
	beq return
	cmp #63
	bne cursor
heim	rts
updown	jsr crestore
	bne up
	lda linus
	clc
	adc #1
	cmp zeile
	bcs unten
	inc nummer
	inc linus
	lda col
	clc
	adc #40
	sta col
	bcc cursor
	inc col+1
	bne cursor
up	lda linus
	beq qup2
	dec nummer
	dec linus
	lda col
	sec
	sbc #40
	sta col
	lda col+1
	sbc #0
	sta col+1
	jmp cursor
return	clc
	rts
qup2	lda nummer
	beq cursor
	jmp up2
unten	ldx nummer
	inx
	cpx anzdrin
	bcs cursor
	txa
	inc nummer
	pha
	jsr suchadr
	pla
	sta nummer
	txa
	pha
	tya
	pha
	lda #startpos+40
	ldy scn
	sta fen
	sty fen+1
	ldx #maxlines
sc1	lda fen
	clc
	adc #40
	sta fn2
	lda fen+1
	adc #0
	sta fn2+1
	ldy breit
sc2	lda (fn2),y
	sta (fen),y
	dey
	bpl sc2
	lda fn2
	sta fen
	lda fn2+1
	sta fen+1
	dex
	bne sc1
sc5	pla
	sta rd+1
	pla
	sta rd
	ldy #0
	sty fin
	jsr ram
	dey
loop5a	iny
	jsr outit
	sta (fen),y
	cpy breit
	bcc loop5a
	jsr rom
	jmp cursor
up2	dec nummer
	lda nummer
	pha
	jsr suchadr
	pla
	sta nummer
	txa
	pha
	tya
	pha
	ldy #<t3
	lda #>t3
	ora scn
	sty fen
	sta fen+1
	ldx #maxlines
sc3	lda fen
	sec
	sbc #40
	sta fn2
	lda fen+1
	sbc #0
	sta fn2+1
	ldy breit
sc4	lda (fn2),y
	sta (fen),y
	dey
	bpl sc4
	lda fn2
	sta fen
	lda fn2+1
	sta fen+1
	dex
	bne sc3
	beq sc5
suchadr	lda #<shell
	ldy #>shell
	sta fen
	sty fen+1
	jsr ram
schleife	lda nummer
	beq gefunden
	ldy #-1
hmm	iny
	lda (fen),y
	bne hmm
	iny
	tya
	clc
	adc fen
	sta fen
	bcc noinc
	inc 1+fen
noinc	dec nummer
	bne schleife
gefunden	ldx fen
	ldy fen+1
	jsr rom
	lda shift
	rts
outit	lda fin
	beq loop7
	lda #160
	rts
loop7	lda (rd),y
	bne loopc
	inc fin
	lda #32
	sty fiy
loopc	bmi loop8
	cmp #32
	bcc loopb
	cmp #$60
	bcc loopa
	and #$df
	bne loopb
loopa	and #$3f
loopb	ora #$80
	rts
loop8	and #$7f
	cmp #$7f
	bne loop9
	lda #$5e
loop9	ora #$40
	bne loopb
optionsout	ldy #0
	lda scn
	sty fen
	sta fen+1
	jsr docol
	ldx #0
ou	lda opt,x
	beq o3
	sta (fen),y
	lda curs
	sta (col),y
	iny
	cpy #17
	bcc o2
	ldy #0
	lda fen
	adc #39
	sta fen
	bcc o2a
	inc fen+1
o2a	jsr docol
o2	inx
	bne ou
o3	ldx scn
	inx
	stx hex4+2
	stx st1+2
	ldy #0
	tya
	ldx #>shell
	jsr hexout
	iny
	iny
	lda write
	ldx write+1
	jsr hexout
	jsr jnout
	jsr breitout
	lda anzdrin
	cmp #-1
	bne no1
	lda #191
st1	sta schirm+90
	bne no4
no1	pha
	lda #<schirm+90
	sta fen
	lda #>schirm+90
	ora scn
	sta fen+1
	pla
	jsr dezout
no4	lda #<shellend-100
	sec
	sbc write
	pha
	lda #>shellend-100
	sbc write+1
	tax
	pla
	ldy #49
hexout	pha
	txa
	jsr hex2
	pla
hex2	pha
	lsr
	lsr
	lsr
	lsr
	jsr hex3
	pla
hex3	and #15
	tax
	lda hex,x
hex4	sta schirm,y
	iny
	rts
dezout	ldy #0
na3	ldx #"0"+128
na2	cmp dez,y
	bcc klainer
	sbc dez,y
	inx
	bne na2
klainer	pha
	txa
st2	sta (fen),y
	pla
	iny
	cpy #3
	bcc na3
	rts
optionsmen	lda #40
	sta col
	lda #>farbram
	sta col+1
	lda #0
	sta menpt
opt1	jsr flare
	beq updn
	cmp #3
	bcc ret
	cmp #63
	bne opt1
	rts
ret	lda menpt
	asl
	tay
	lda adr,y
	sta jump+1
	lda adr+1,y
	sta jump+2
jump	jsr 0
	jmp opt1
updn	jsr crestore
	bne rauf
	lda menpt
	cmp #4
	bcs opt1
	inc menpt
	lda col
	clc
	adc #40
	sta col
	bcc opt1
	inc col+1
	bne opt1
rauf	lda menpt
	beq opt1
	dec menpt
	lda col
	sec
	sbc #40
	sta col
	lda col+1
	sbc #0
	sta col+1
	bne opt1
reset	jmp (resvkt)
takejn	lda takeprg
	eor #1
	sta takeprg
	jmp jnout
cbreit	lda shift
	bne down
	lda breit
	cmp #36
	bcs noch
	inc breit
noch	jmp breitout
down	lda breit
	beq noch
	dec breit
	bpl noch
quit	lda konf0
	and #127
	sta konf0
	php
	sei
	lda oldirq
	ldy oldirq+1
	sta irqvec
	sty irqvec+1
	lda #<inold
	ldy #>inold
	sta invec
	sty invec+1
	plp
	pla
	pla
	rts
cleara	lda #0
	sta anzdrin
	lda #<shell
	ldy #>shell
	sta write
	sty write+1
	sta owrite
	sty owrite+1
	pla
	pla
	pla
	pla
	jmp intro
losgehts	lda #<newget
	ldy #>newget
	sta invec
	sty invec+1
	lda #0
	sta anzdrin
	sta keylock
	sta keylock+1
	lda #<shell
	ldy #>shell
	sta write
	sty write+1
	sta owrite
	sty owrite+1
	lda #32
	sta breit
	sei
	lda irqvec+1
	cmp #>newirq
	beq sat
	sta oldirq+1
	lda irqvec
	sta oldirq
	lda #<newirq
	ldy #>newirq
	sta irqvec
	sty irqvec+1
sat	cli
	lda konf0
	ora #128
	sta konf0
	lda #<hello
	ldy #>hello
	jmp strout
newget	jsr getline
	stx chrget
	sty chrget+1
	sei
	jsr inshell
	cli
	jmp incont
fini	rts
inshell	jsr testvoll
	beq fini
	lda write
	ldy write+1
	sta tmp
	sty tmp+1
	ldy #-1
into	iny
	lda puff,y
	sta (tmp),y
	beq null
	lda tmp+1
	cmp #>shellend-$100
	bcc into
	bne voll
	lda tmp
	cmp #<shellend-100
	bcc into
voll	lda #1
	sta nummer
	jsr suchadr
	stx tmp
	sty tmp+1
	jsr ram
	ldy #0
	lda #<shell
	sta fen
	lda #>shell
	sta fen+1
transfer	lda (tmp),y
	sta (fen),y
	inc fen
	bne nok
	inc fen+1
nok	inc tmp
	bne noi
	inc tmp+1
noi	lda tmp+1
	cmp write+1
	bcc transfer
	bne feddisch
	lda tmp
	cmp write
	bcc transfer
feddisch	lda fen
	sta write
	lda fen+1
	sta write+1
	dec anzdrin
	jsr rom
	bne inshell
null	lda write
	sta owrite
	lda write+1
	sta owrite+1
	inc anzdrin
	bne safe
	dec anzdrin
safe	iny
	tya
	clc
	adc write
	sta write
	lda write+1
	adc #0
	sta write+1
	rts
newirq	jsr irq1
	jsr irq2
	jmp (oldirq)
irq1	lda flag
	bne an
off	rts
an	lda numbkey
	bne off
	jsr ram
	ldy #0
	lda (from),y
	beq nuell
rein	sta keybuf
	inc numbkey
	inc from
	bne rueck
	inc from+1
rueck	jmp rom
nuell	lsr flag
	jsr rom
	lda #64
	sta timer
	lda modus
	beq rueck
	lda #cr
	bne rein
irq2	lda quote
	bne off
	lda numbkey
	bne off
	lda anzdrin
	beq off
	lda key
	cmp oldkey
	beq off
	sta oldkey
	cmp #3
	bne nf78
	lda shift
	ldx owrite
	ldy owrite+1
	jmp putfrom
nf78	cmp #4
	beq f1
	cmp #5
	beq options
	rts
f1	jsr savescreen
	lda #rundel
	sta delay
	jsr windowout
	bcs cancel
	jsr suchadr
	jsr putfrom
cancel	jsr loadscreen
	lda #0
	sta numbkey
	rts
options	jsr savescreen
	lda #rundel
	sta delay
intro	jsr optionsout
	jsr optionsmen
	jmp cancel
